const { defineConfig } = require("@vue/cli-service");
const AutoImport = require("unplugin-auto-import/webpack");
const Components = require("unplugin-vue-components/webpack");
const { ElementPlusResolver } = require("unplugin-vue-components/resolvers");

module.exports = defineConfig({
    transpileDependencies: ["/electron-log/"],
    productionSourceMap: false, //去掉打包的时候生成的map文件
    lintOnSave: false, // 引入插件不使用时不报错
    configureWebpack: {
        plugins: [
            AutoImport({
                resolvers: [ElementPlusResolver()],
            }),
            Components({
                resolvers: [ElementPlusResolver()],
            }),
        ],
        externals: {
            electron: 'require("electron")',
        },
        devServer: {
            port: "16616", //端口号
        },
    },

    // 第三方插件配置
    pluginOptions: {
        // vue-cli-plugin-electron-builder 配置
        electronBuilder: {
            nodeIntegration: true,
            // 设置应用主进程的入口
            mainProcessFile: "src/background.js",
            // 设置应用渲染进程的入口
            rendererProcessFile: "src/main.js",
            customFileProtocol: "../",
            // 打包选项
            builderOptions: {
                asar: false,
                // 解决的问题：在安装到电脑后，系统通知无法工作
                appId: "com.electron.httprunner", // 软件id
                copyright: "08051005",
                productName: "httprunner-cli", // 打包后的名称
                directories: {
                    output: "build-electron", // 安装包生成目录
                },
                // windows系统相关配置
                win: {
                    // 应用图标路径（Windows 系统中 icon 需要 256 * 256 的 ico 格式图片）
                    // icon: "./public/logo.ico",
                    target: {
                        target: "nsis",
                        // 支持 64 位的 Windows 系统
                        arch: ["x64"],
                    },
                },
                extraResources: [
                    {
                        from: "./public/requirements.txt",
                        to: "./",
                    },
                    {
                        from: "./public/httprunnerServer.py",
                        to: "./",
                    },
                ],
                nsis: {
                    // 如果为false，想要给电脑所有用户安装必须使用管理员权限
                    allowElevation: true,
                    // 是否一键安装
                    oneClick: false,
                    // 允许修改安装目录
                    allowToChangeInstallationDirectory: true,
                    guid: "com.electron.httprunner", // 软件id
                    // include: "./installer.nsh",
                    deleteAppDataOnUninstall: true, //删除用户数据
                    // installerIcon: "./public/logo.ico", //安装logo
                    // installerHeaderIcon: "./public/logo.ico", //安装logo
                },
            },
        },
    },
});
